const { ccclass, property } = cc._decorator;

@ccclass
export default class WithDrawOptionCtrl extends cc.Component {
    @property(cc.Node)
    ui = null;

    @property
    option_index = null;

    @property
    ratio = null;

    @property
    city_id = null;

    @property
    isChose = false;

    onLoad() {
        this.onUILoad();
        this.addButtonListen();
        this.initUI();
        this.oppoReview();
        this.dealReplacePlaceName();
    }

    start() {}

    oppoReview() {
        if (d.isOppoChannel()) {
            _[2] = "到达终点";
        }
    }

    dealReplacePlaceName() {
        let e = n.isDmthFlag();
        let t = l.isHitOppoReviewBan();

        if (n.getDmth2Ab1()) {
            _[2] = "到达终点";
        } else if (n.getDmth2Ab2()) {
            _[2] = "到达长城";
        } else if (e) {
            _[2] = t ? "到达终点" : "到达京城";
        } else if (d.isOppoChannel()) {
            _[2] = "到达终点";
        }
    }

    onUILoad() {
        this.ui = this.node.addComponent(f);
    }

    addButtonListen() {
       UiManager.addButtonListen(this.node, this.clickOption, this);
    }

    clickOption() {
        u.log("点击选项======", this.option_index, this.ratio);
        this.showOneSelect();
        s.trigger(c.WITHDRAW_TIPS_SHOW, {
            option_index: this.option_index,
            ratio: this.ratio
        });
    }

    initData(e) {
        if (e) {
            this.option_index = e.option_index;
            this.city_id = e.city_id;
            this.ratio = e.ratio;
        }
    }

    initUI() {
        let e = this.toDecimal(100 * this.ratio);
        this.ui.withDrawTips.getComponent(cc.Label).string = e + "%";
        let t = l.getExtractInfo();
        if (this.option_index === 0) {
            this.ui.conditionLabel.getComponent(cc.Label).string = _[0];
        } else if (this.option_index == t.length - 1) {
            this.ui.blueBg.active = false;
            this.ui.redBg.active = true;
            this.ui.conditionLabel.getComponent(cc.Label).string = _[2];
        } else {
            let a = _[1];
            a = a.replace(/cityId/g, this.city_id.toString());
            this.ui.conditionLabel.getComponent(cc.Label).string = a;
        }
    }

    toDecimal(e) {
        let t = parseFloat(e);
        if (!isNaN(t)) {
            return Math.round(100 * e) / 100;
        }
    }

    setIsChose(e) {
        this.isChose = e;
        this.ui.commonBg.active = !e;
        this.ui.selectBg.active = e;
        if (e) {
            this.ui.txDes.color = p.getColor("#EC3D1F");
            this.ui.withDrawTips.color = p.getColor("#EC3D1F");
        } else {
            this.ui.txDes.color = p.getColor("#99643C");
            this.ui.withDrawTips.color = p.getColor("#99643C");
        }
    }

    showOneSelect() {
        let e = this.node.parent.children;
        for (let t = 0; t < e.length; t++) {
            let o = e[t].getComponent(a);
            if (o.option_index === this.option_index) {
                o.setIsChose(true);
            } else {
                o.setIsChose(false);
            }
        }
    }
}
